package com.webank.weideagroup2.kit;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.webank.weideagroup2.bean.CommonRecord;
import com.webank.weideagroup2.bean.Record;
import com.webank.weideagroup2.bean.ResultCode;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class CommonRecordKit {


    public static Record setRecord(JSONObject jsonObject, CommonRecord record, String platform){

        try {
            String mileage = jsonObject.getString("mileage");
            record.setMileage(mileage);
        }catch (JSONException e){
            record.setMileage(null);
        }
        record.setPlatform(platform);
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        record.setDate(format.format(new Date()));

        try{
            if(jsonObject.getJSONArray("picture") != null){
                record.setPicture( jsonObject.getJSONArray("picture").toJavaList(String.class));

            }
        }catch (JSONException e){
            record.setPicture(null);
        }
        try{
            record.setDescription(jsonObject.getString("description"));
        }catch (JSONException e){
            record.setDescription(null);
        }

        return record;
    }

    public static boolean judgeRecord(CommonRecord commonRecord){

        if (commonRecord.getMileage() == null || commonRecord.getVIN().length() != 17) {
            return false;
        }
        return true;
    }

}
